-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UseLambdaForFunctionalInterface
recipe should not convert when code uses a static field from enum constructor
#415
Conversation
… uses a static field from enum constructor
… uses a static field from enum constructor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions could not be made:
- src/main/java/org/openrewrite/staticanalysis/CovariantEquals.java
- lines 80-80
- src/main/java/org/openrewrite/staticanalysis/EmptyBlockVisitor.java
- lines 215-216
- src/main/java/org/openrewrite/staticanalysis/ExplicitInitializationVisitor.java
- lines 72-72
- lines 94-94
- src/main/java/org/openrewrite/staticanalysis/FinalizeMethodArguments.java
- lines 208-208
- src/main/java/org/openrewrite/staticanalysis/HiddenFieldVisitor.java
- lines 199-199
- lines 244-244
- src/main/java/org/openrewrite/staticanalysis/HideUtilityClassConstructorVisitor.java
- lines 98-98
- lines 128-128
- lines 191-191
- src/main/java/org/openrewrite/staticanalysis/NoRedundantJumpStatements.java
- lines 98-98
- src/main/java/org/openrewrite/staticanalysis/OperatorWrap.java
- lines 96-96
- lines 134-134
- lines 182-182
- lines 215-215
- lines 246-246
- lines 283-283
- lines 316-316
- lines 364-364
- lines 397-397
- src/main/java/org/openrewrite/staticanalysis/RenameMethodsNamedHashcodeEqualOrToString.java
- lines 69-70
- src/main/java/org/openrewrite/staticanalysis/ReplaceDuplicateStringLiterals.java
- lines 249-249
- src/main/java/org/openrewrite/staticanalysis/TernaryOperatorsShouldNotBeNested.java
- lines 357-357
- src/main/java/org/openrewrite/staticanalysis/UseLambdaForFunctionalInterface.java
- lines 73-73
- lines 117-117
…ot-convert-when-code-uses-a-static-field-from-enum-constructor
Thanks for taking this on! From a reasoning and maintenance perspective I want to propose an alternative: not make any change within Enums. @Override
public J visitClassDeclaration(J.ClassDeclaration classDecl, ExecutionContext ctx) {
if (classDecl.getKind() == J.ClassDeclaration.Kind.Type.Enum) {
return classDecl;
}
return super.visitClassDeclaration(classDecl, ctx);
} Given that we rarely expect any lambdas within enum classes, I think it's fair to then just ignore any such cases if they occur. It would greatly simplify the logic here, and cover 3 out of the 5 tests you've written here, with the other 2 ignored to likely little effect. Saves us from then having to reason about and maintain these conditionals for any such edge cases. Any thoughts on that? |
Well actually: "Given that we rarely expect any So let's simplify it indeed. I will change the code and modify the test accordingly 😎. |
What's changed?
No more lambda conversion for
UseLambdaForFunctionalInterface
recipe when the anonymous class is within a constructor of a Enum class and uses a static field of this very class.What's your motivation?
UseLambdaForFunctionalInterface
should not convert when code uses a static field from enum constructor #413Checklist